<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/sys/msg" id="goBack" data-pjax><i
                class="ti-angle-left"></i>${msg['globals.button.back']}</a>
    </div>
    <div class="pull-right offscreen-right">
        <button id="save" class="btn btn-primary navbar-btn">发送</button>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/sys/msg/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="type" class="col-sm-2 control-label">消息类型(*)</label>
                            <div class="col-sm-8">
                                <select id="type" name="type" class="form-control" data-parsley-required="true">
                                    <option value="">请选择消息类型</option>
                                    <option value="system">系统消息</option>
                                    <option value="user">用户消息</option>
                                </select>
                            </div>
                        </div>
                        <div id="selUser" class="form-group" style="display: none">
                            <label for="users" class="col-sm-2 control-label">选择用户(*)</label>
                            <div class="col-sm-8" style="display: table">
                                <input id="users" name="users" type="text" class="form-control input-sm"
                                       placeholder="" readonly data-parsley-required="false">
                                <span class="input-group-btn">
                                     <a class="btn btn-default btn-sm" type="button"
                                             href="${base}/platform/sys/msg/selectUser" data-toggle="modal" data-target="#dialogUserSelect" >选择用户</a>
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">消息标题(*)</label>
                            <div class="col-sm-8">
                                <input type="text" id="title" class="form-control" name="title"
                                       data-parsley-required="true" placeholder="消息标题(50字以内)" data-parsley-maxlength="50">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="note" class="col-sm-2 control-label">消息内容(*)</label>
                            <div class="col-sm-8">
                                <textarea id="note" class="form-control" name="note" data-parsley-required="true"
                                          data-parsley-maxlength="500" placeholder="消息内容(500字以内)" cols="20"
                                          rows="10"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">消息URL</label>
                            <div class="col-sm-8">
                                <input type="text" id="url" class="form-control" name="url" placeholder="http://">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
            </form>
        </section>
    </div>
</div>
<div id="dialogUserSelect" class="modal fade bs-modal-sm" tabindex="-3" role="dialog" aria-hidden="true">
    <div class="modal-dialog" style="width: 700px;">
        <div class="modal-content" style="width: 700px;">

        </div>
    </div>
</div>
<script language="JavaScript">
    $(document).ready(function () {
        $("#dialogUserSelect").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
        $("#type").on("change",function () {
            $("#selUser").hide();
            $("#users").attr("data-parsley-required","false");
            if($(this).val()=="user"){
               $("#selUser").show();
               $("#users").attr("data-parsley-required","true");
            }
        });
        $("#save").on("click",function () {
            $('#addForm').submit();
        });
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    form.resetForm();
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>
<%}%>


